package isogame{
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import isogame.DataParser;
	import isogame.Event.FileLoaderEvent;
	import isogame.Event.DataEvent;
	
	public class Data extends EventDispatcher{
		
		private var count:Number;
		private var dataHold:Array = new Array;
		private var f:DataParser;
		private var data:Array;
		
		//---------------------------------------
		// CONSTRUCTOR
		//---------------------------------------
		
		public function Data(data:Array){
			count = 0;
			this.data = data;
			
			load();
		}
		
		//---------------------------------------
		// GETTER / SETTERS
		//---------------------------------------
		
		public function get dataHolder():Array{
			return dataHold;
		}
		
		
		//---------------------------------------
		// PUBLIC METHODS
		//---------------------------------------
		
		
		//---------------------------------------
		// PRIVATE METHODS
		//---------------------------------------
		
		private function load():void{
			f= new DataParser(data[count]);
			f.addEventListener(FileLoaderEvent.SUCCESS, countUp);
		}
		
		private function countUp(evnt:Event):void{
			dataHold[data[count]] = f.bitmap;
				
			count++;
			if(count == data.length){
				var dataDone:DataEvent = new DataEvent("success");
				dispatchEvent(dataDone);
			}else{
				load();
			}
		}
		
	}// end class
}// end package